package Experiment;

/**
 * 设计诸如以下页面的简单计算器 （加减乘除），将加减乘除部分写在JavaBean中，在JSP页面中调用显示计算结果。
 * 要求：主页面JSP中，设置供客户端输入的文本框。并显示最终计算结果；当除数为零时提示报错。
 */
public class Add {
    float num1;
    float num2;
    String symbol;
    float result;

    public float getNum1() {
        return num1;
    }

    public void setNum1(float num1) {
        this.num1 = num1;
    }

    public float getNum2() {
        return num2;
    }

    public void setNum2(float num2) {
        this.num2 = num2;
    }

    public String getSymbol() {
        return symbol;
    }

    public void setSymbol(String symbol) {
        this.symbol = symbol;
    }

    public float getResult() {
        float results = 0;
        try {
            switch (symbol) {
                case "加":
                    results = num1 + num2;
                    break;
                case "减":
                    results = num1 - num2;
                    break;
                case "乘":
                    results = num1 * num2;
                    break;
                case "除":
                    results = num1 / num2;
                    break;

                default:
                    break;
            }
        } catch (Exception e) {
            e.getMessage();
        }
        return results;
    }

    public void setResult(float result) {
        this.result = result;
    }
}